import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-23
 * Time: 10:44
 */
public class missing_Two {
    public static int[] missingTwo(int[] nums) {
        //两个数组先异或
        int num = 0;
        for (int x : nums) {
            num ^= x;
        }

        for (int i = 1; i <= nums.length + 2; i++) {
            num ^= i;
        }

        //找出第一的为1的bit位
        int tmp = 0;
        while (((num >> tmp) & 1) != 1) {
            tmp++;
        }
        //分类
        int[] ret = new int[2];
        for (int x : nums) {
            if (((x >> tmp) & 1) == 1) {
                ret[0] ^= x;
            } else {
                ret[1] ^= x;
            }
        }
        for (int i = 1; i <= nums.length + 2; i++) {
            if (((i >> tmp) & 1) == 1) {
                ret[0] ^= i;
            } else {
                ret[1] ^= i;
            }
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] nums={2};
        System.out.println(Arrays.toString(missingTwo(nums)));
    }

}
